package com.entities.report.list;

import com.core.protocols.ICustomDatasourceDelegate;
import com.core.protocols.IReportExecuteDatasource;
import com.core.protocols.ITableViewDatasource;
import com.core.protocols.ITableViewDelegate;
import com.core.ui.customcell.TableViewCell;
import com.core.ui.customcell.TableViewDataCell;
import com.core.ui.customview.TableViewHeaderCell;
import com.core.utils.IndexPath;


public class ReportExecuteListController
        implements ITableViewDatasource, ITableViewDelegate, ICustomDatasourceDelegate {

	// private List <Object> objects;
	private ICustomDatasourceDelegate delegate;



	@Override
	public void refreshContent () {

		// objects = new ArrayList <Object>();
		// int itemsCount = this.datasource.numberOfItems();
		// for ( int i = 0; i < itemsCount; i++ ) {
		// objects.add();
		// }


	}



	@Override
	public void setCustomDatasourceDelegate ( ICustomDatasourceDelegate delegate ) {

		this.delegate = delegate;

	}



	@Override
	public void reloadData () {

		delegate.refreshContent();

	}



	@Override
	public String tableStyleClassName () {

		// TODO Auto-generated method stub
		return null;
	}



	@Override
	public String headerRowStyleClassNameAtIndex ( int index ) {

		// TODO Auto-generated method stub
		return null;
	}



	@Override
	public String headerCellStyleClassNameAtIndexPath ( IndexPath indexPath ) {

		// TODO Auto-generated method stub
		return null;
	}



	@Override
	public String cellStyleClassNameAtIndexPath ( IndexPath indexPath ) {

		// TODO Auto-generated method stub
		return null;
	}



	@Override
	public String rowStyleClassNameAtIndex ( int index ) {

		// TODO Auto-generated method stub
		return null;
	}



	@Override
	public int numberOfHeadRows () {

		// TODO Auto-generated method stub
		return 1;
	}



	@Override
	public int numberOfHeadCols () {

		// TODO Auto-generated method stub
		return this.datasource.numberOfColumns();
	}



	@Override
	public TableViewHeaderCell headCellAtIndexPath ( IndexPath indexPath ) {

		TableViewHeaderCell result = new TableViewHeaderCell();
		result.setStyleName("headerCellSimple");
		result.setText(this.datasource.columnAtIndex(indexPath.getCol()));
		return result;
	}



	@Override
	public int numberOfDataRows () {

		return this.datasource.numberOfItems();
	}



	@Override
	public int numberOfDataCols () {

		// TODO Auto-generated method stub
		return this.datasource.numberOfColumns();
	}



	@Override
	public TableViewCell dataCellAtIndexPath ( IndexPath indexPath ) {

		// Object item = this.objects.get(indexPath.getRow());
		TableViewDataCell result = new TableViewDataCell();
		result.setStyleName("dataCellSimple maxwidth");
		Object obj = this.datasource.itemAtIndexPath(indexPath);
		if ( obj != null ) {
			Class <?> clazz = obj.getClass();
			if ( clazz.isAssignableFrom(String.class) ) {
				result.setText((String) obj);
			} else {

			}
		}

		return result;
	}

	private IReportExecuteDatasource datasource;



	public IReportExecuteDatasource getDatasource () {

		return datasource;
	}



	public void setDatasource ( IReportExecuteDatasource datasource ) {

		this.datasource = datasource;
	}

}
